import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_baby_health_tracker/screens/note.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:intl/intl.dart';
import 'package:table_calendar/table_calendar.dart';

import '../widgets/card.dart';

class CalendarScreen extends StatefulWidget {
  const CalendarScreen({super.key});

  @override
  State<CalendarScreen> createState() => _CalendarScreenState();
}

class _CalendarScreenState extends State<CalendarScreen> {

  DateTime _selectDate  = DateTime.now();


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('日历'),
        actions: [
          IconButton(onPressed: (){
            Get.to(NoteListScreen());
          }, icon: Icon(Icons.notes))
        ],
      ),
      body: Column(
        children: [
          TableCalendar(
            calendarStyle: CalendarStyle(
              todayDecoration: BoxDecoration(
                color: Colors.green,
                shape: BoxShape.circle,
              )
            ),
            onFormatChanged: (f){

            },
            onDaySelected: (selectedDay, focusedDay){
              setState(() {
                _selectDate = selectedDay;

              });
            },
            locale: 'zh_CN',
            currentDay: _selectDate,
            focusedDay: _selectDate, firstDay: DateTime.utc(2010, 10, 16), lastDay: DateTime.utc(2099, 9, 9),),
          SizedBox(
            height: 8,
          ),
          Divider(
            height: 1,
          ),
          SizedBox(
            height: 8,
          ),
          LiCard(
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('每日总结',style: TextStyle(
                      color: Colors.green,
                      fontWeight: FontWeight.bold
                    ),),
                    Text(DateFormat.MMMMd('zh_CN').format(_selectDate))
                  ],
                ),
                ListTile(
                  title: Text('1分组前，30分钟，奶瓶'),
                  leading: Container(
                      padding: EdgeInsets.all(8),
                      decoration: BoxDecoration(
                          color: Colors.amber,
                          shape: BoxShape.circle
                      ),
                      child: Icon(Icons.local_drink,color: Colors.black54,size: 18,)),
                  dense: true,
                  contentPadding: EdgeInsets.zero,
                ),
                ListTile(
                  title: Text('1分组前，30分钟，奶瓶'),
                  leading: Container(
                      padding: EdgeInsets.all(8),
                      decoration: BoxDecoration(
                          color: Colors.amber,
                          shape: BoxShape.circle
                      ),
                      child: Icon(Icons.local_drink,color: Colors.black54,size: 18,)),
                  dense: true,
                  contentPadding: EdgeInsets.zero,
                ),
                ListTile(
                  title: Text('1分组前，30分钟，奶瓶'),
                  leading: Container(
                      padding: EdgeInsets.all(8),
                      decoration: BoxDecoration(
                          color: Colors.amber,
                          shape: BoxShape.circle
                      ),
                      child: Icon(Icons.local_drink,color: Colors.black54,size: 18,)),
                  dense: true,
                  contentPadding: EdgeInsets.zero,
                ),
              ],
            ),
          ),
          LiCard(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('笔记',style: TextStyle(
                        color: Colors.green,
                        fontWeight: FontWeight.bold
                    ),),
                    Text(DateFormat.MMMMd('zh_CN').format(_selectDate))
                  ],
                ),
                GestureDetector(
                  onTap: (){
                    Get.to(NoteEditScreen(day: _selectDate));
                  },
                  child: Container(
                      margin: EdgeInsets.only(top: 8),
                      padding: EdgeInsets.all(8),
                      child: Text('添加笔记',style: TextStyle(
                        color: Colors.grey
                      ),)),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
